import axios from "axios";
import qs from "qs";



// axios.defaults.baseURL = "https://api.rubysci.com/api";
// export const uploadUrl = "https://api.rubysci.com/api/admin/upload";
// export const uploadEditUrl = 'https://api.rubysci.com/api/admin/upload_edit_img';
// export const exportFile = 'https://api.rubysci.com/api/zh/export?id=';

axios.defaults.baseURL = "http://localhost:8000/api";
export const uploadUrl = "http://localhost:8000/api/admin/upload";
export const uploadEditUrl = 'http://localhost:8000/api/admin/upload_edit_img';
export const exportFile = 'http://localhost:8000/api/zh/export?id=';
// 1、请求拦截
axios.interceptors.request.use(
    config => {
        if (!config.url.startsWith("/admin")){
            return config;
        }
        let token = window.localStorage.getItem('token');
        config.headers.Authorization = "Bearer " + token;
        return config;
    },
    error => {
        return Promise.reject(error);
    }
);
export default {
    post(url, data){
        return new Promise((resolve, reject) =>{
            axios({
                method: 'post',
                url,
                data: qs.stringify(data)
            }).then(res =>{
                resolve(res.data)
            }).catch(err=>{
                reject(err)
            })
        })
    }
}